package pixelwaks.gui.impl;

import java.awt.Color;
import java.awt.Dimension;
import java.util.List;
import java.util.ResourceBundle;

import javax.swing.BorderFactory;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.border.Border;
import javax.swing.border.EtchedBorder;

import common.gui.IViewable;
import common.i18n.ChangeLanguage;
import common.i18n.IChangeLanguage;

import pixelwaks.ctrl.ControlFactory;
import pixelwaks.ctrl.impl.ModeCtrl;

public class InfoModePanel extends JPanel implements IChangeLanguage, IViewable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	JTextArea info = new JTextArea();
	private Border sgsSBorder = BorderFactory.createEtchedBorder(EtchedBorder.RAISED);
	List<String> l;

	public InfoModePanel() {
		ChangeLanguage.addObserver(this);
		info.setEditable(false);
		info.setLineWrap(true);
		info.setWrapStyleWord(true);
		info.setPreferredSize(new Dimension(495,128));
		ControlFactory.getObserver(ControlFactory.MODE_CTRL).addView(this);
		add(info);
		
		setBorder(sgsSBorder);
		setPreferredSize(new Dimension(500,150));
		setVisible(true);
		setBackground(Color.white);
	}
	
	@Override
	public void setLanguage(ResourceBundle rb) {
		ModeCtrl mctrl = (ModeCtrl) ControlFactory.getObserver(ControlFactory.MODE_CTRL);
		String mode = mctrl.getSelectedMode();
		
		if(!mode.equals("")) {
			String info = rb.getString(mode);
			updateView(info);
		}
	}
	
	@Override
	public void updateView(Object o) {		
		
		info.setText(o.toString());
	}
	
//	@Override
//	public void updateView(Object o) {
//		String s = "";
//		String l;
//				File f = new File("./resource" + File.separator + "modes" + File.separator + o + ".mode");
//				if(!f.exists())
//					f = new File("./resource" + File.separator + "modes" + File.separator + "default.mode");
//				try {
//					BufferedReader br = new BufferedReader(new FileReader(f));
//					while ((l = br.readLine()) != null) {
//						s = s + l;
//					}
//					info.setText(s);
//					
//						
//					
//				} catch (Exception e) {
//					// TODO Auto-generated catch block
//					e.printStackTrace();
//				}
////			}
////		}
//		
//	}


}
